import DatePicker from 'vue-datepicker'
import Tab from '../tab/tab.vue'
import Pages from '../../../pages/pages.vue'
import { showMsg, setMenuType, getShareList } from '../../../../vuex/action'

export default {
  name: 'promoter-list',
  components: {
    'vue-tab': Tab,
    'vue-pages': Pages,
    'vue-date-picker': DatePicker
  },
  data() {
    return {
      list: [],
      status: -1,
      pages: {
        start: 0,
        totalPages: 0,
        limit: 20
      }
    }
  },
  computed: {
    phone() {
      return this.$route.params.phone || this.$route.query.phone
    }
  },
  vuex: {
    actions: {
      xShowMsg: showMsg,
      xSetMenuType: setMenuType,
      xGetShareList: getShareList
    }
  },
  ready() {
    this.xSetMenuType('activity')
    this.getList()
  },
  methods: {
    getList() {
      var params = {
        phone: this.phone,
        start: this.pages.start,
        limit: this.pages.limit
      }
      if (this.status > 0) {
        params.status = this.status
      }
      this.xGetShareList(params)
        .then((data) => {
          this.list = data.list
          this.pages.totalPages = Math.ceil(data.totalCount / params.limit)
        })
        .catch((res) => {
          this.xShowMsg({
            type: 'danger',
            content: res.error_msg
          })
        })
    }
  },
  watch: {
    checkAll() {
      this.checkedNames = []
      for (var item of this.list) {
        if (this.checkAll) {
          this.checkedNames.push(item.id + '')
        }
      }
    },
    checkedNames() {
      if (this.checkedNames.length === 0) {
        this.noSelectUser = true
      } else {
        this.noSelectUser = false
      }
    }
  }
}
